home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / langguid / chap_05 / xmpl_02.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  792 b   |  32 lines  |  [TEXT/ttxt]

  1. --<<<
  2. -- Kaleida Labs, Inc.
  3. -- Field Guide to the ScriptX Language
  4. -- chapter 5, example 2
  5.  
  6. -- addEmUp takes a variable number of arguments, sums them all
  7. -- and returns the sum
  8. function addEmUp #rest numlist -> (
  9.     local sumArgs := 0
  10.     for i in numlist do sumArgs := sumArgs + i
  11. )
  12. addEmUp 1 2 3 4 5
  13. addEmUp 3 4
  14.  
  15.  
  16. -- joinArray takes a single required array and a variable number
  17. -- of other arrays.  It builds a single array of all the 
  18. -- elements in all its arguments
  19. function joinArray array1 #rest otherarrays -> (
  20.     for i in otherarrays do addMany array1 i
  21.     return array1
  22. )
  23. joinArray #(1,2,3) #(4,5,6)
  24. joinArray #() #(@angora,@persian) #(@egyptianmau) #(@housecat)
  25.  
  26.  
  27. function showRest #rest args #key a: b: c:(100) ->
  28.     print args debug
  29. showRest a:10 b:20 c:30
  30. showRest a:10
  31. showRest()
  32. -->>>